package com.iamalive;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.http.entity.StringEntity;

import android.content.Context;
import android.widget.Toast;

public class Utils {
    /**
     * The following method verifies if the given email address is legal or not.
     *
     * @param emailAddress
     *            the email address
     * @return true if the email address is valid, false otherwise.
     */
    public static boolean isValidEmailAddress(final String emailAddress) {
/*        try {
            new InternetAddress(emailAddress, true);
        } catch (AddressException ae) {
            return false;
        } */

        return true;
    }
    
    public static boolean isValidPhoneNum(final String phoneNum) {
    	return true;
    }
    
    public static boolean isValidImId(final String imId) {
    	return true;
    }
    
    public static boolean isValidZip(final String zipCode) {
    	return true;
    }
    

    public static void showToast(Context appContext, String message) {
    	Toast.makeText(appContext, message, Toast.LENGTH_LONG).show();
    }
    
	public static void removeExistingStringEntries(ArrayList<String> dest, ArrayList<String> src) {
		Iterator<String> it = src.iterator();
		while (it.hasNext()) {
			String existingEntry = it.next();
			dest.remove(existingEntry);		    
		}
	}
	
	public static StringEntity getStringEntity(String xmlString) {
		StringEntity xmlEntity = null;
		try {
			xmlEntity = new StringEntity(xmlString.toString());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		xmlEntity.setContentEncoding("UTF-8");
		
		return xmlEntity;
	}
	
	public  static String convertStreamToString(InputStream is) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		StringBuilder sb = new StringBuilder();

		String line = null;
		try {
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
	            }
	        } catch (IOException e) {
	        	e.printStackTrace();
	        } finally {
	        	try {
	        		is.close();
	        	} catch (IOException e) {
	        		e.printStackTrace();
	        	}
	        }
			return sb.toString();
	}

}
